﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using POSPlus.DatabaseOperations;

namespace POSPlus.EZBarTender.DatabaseOperations
{
	public class Tag : DatabaseObject
	{
		private JobType _jobType;

		public String Description { get; set; }
		public int Vendor { get; set; }
		public String CertCode { get; set; }
		public double AvgDailyMovement { get; set; }
		public short Pack { get; set; }
		public String Size { get; set; }
		public double UnitNp { get; set; }
		public String Uom { get; set; }
		public int Hosted { get; set; }
		public short PriceMethod { get; set; }
		public decimal NormalPrice { get; set; }
		public decimal GroupPrice { get; set; }
		public short Quantity { get; set; }
		public String Upc { get; set; }
		public int LocAisle { get; set; }
		public int LocBlock { get; set; }
		public int LocSeq { get; set; }
		public DateTime PrintDate { get; set; }
		public short SpecialPriceMethod { get; set; }
		public decimal SpecialPrice { get; set; }
		public decimal SpecialGroupPrice { get; set; }
		public short SpecialQuantity { get; set; }
		public int PalletCode { get; set; }
		public double UnitSp { get; set; }
		public String WhereToBuy { get; set; }
		public DateTime StartDate { get; set; }
		public DateTime EndDate { get; set; }
		public String Rehang { get; set; }
		public DateTime DealEndDate { get; set; }
		public String TagType { get; set; }
		public String BatchNo { get; set; }
		public String JobName { get; set; }

		public Tag(String connectionString)
		{
			ConnectionString = connectionString;
			PopulateDefault();
		}

		public Tag(String connectionString, String upc, int locAisle, int locBlock, int locSeq)
		{
			ConnectionString = connectionString;
			using (SqlConnection connection = new SqlConnection(ConnectionString))
			{
				connection.Open();
				using (SqlCommand command = new SqlCommand("SELECT * FROM POSplus_TagPrinting WHERE Upc = @Upc " +
					"AND ISNULL(LocAisle,0) = ISNULL(@LocAisle,0) AND ISNULL(LocBlock,0) = ISNULL(@LocBlock,0) AND ISNULL(LocSeq,0) = ISNULL(@LocSeq,0)",
					connection))
				{
					command.Parameters.AddWithValue("@Upc", upc);
					command.Parameters.AddWithValue("@LocAisle", locAisle);
					command.Parameters.AddWithValue("@LocBlock", locBlock);
					command.Parameters.AddWithValue("@LocSeq", locSeq);
					using (SqlDataReader reader = command.ExecuteReader())
					{
						if (reader.Read())
						{
							Description = DatabaseObject.FromDB<String>(reader["Description"]);// Convert.ToString(reader["Description"]);
							Vendor = DatabaseObject.FromDB<Int32>(reader["Vendor"]);// Convert.ToInt32(reader["Vendor"]);
							CertCode = DatabaseObject.FromDB<String>(reader["Cert_Code"]);// Convert.ToString(reader["CertCode"]);
							AvgDailyMovement = DatabaseObject.FromDB<Double>(reader["AvgDailyMovement"]);// Convert.ToDouble(reader["AvgDailyMovement"]);
							Pack = DatabaseObject.FromDB<Int16>(reader["Pack"]);// Convert.ToInt16(reader["Pack"]);
							Size = DatabaseObject.FromDB<String>(reader["Size"]);// Convert.ToString(reader["Size"]);
							UnitNp = DatabaseObject.FromDB<Double>(reader["Unit_NP"]);// Convert.ToDouble(reader["UnitNp"]);
							Uom = DatabaseObject.FromDB<String>(reader["Uom"]);// Convert.ToString(reader["Uom"]);
							Hosted = DatabaseObject.FromDB<Int32>(reader["Hosted"]);// Convert.ToInt32(reader["Hosted"]);
							PriceMethod = DatabaseObject.FromDB<Int16>(reader["PriceMethod"]);// Convert.ToInt16(reader["PriceMethod"]);
							NormalPrice = DatabaseObject.FromDB<decimal>(reader["Normal_Price"]);// Convert.ToDouble(reader["Normal_Price"]);
							GroupPrice = DatabaseObject.FromDB<decimal>(reader["GroupPrice"]);// Convert.ToDouble(reader["GroupPrice"]);
							Quantity = DatabaseObject.FromDB<Int16>(reader["Quantity"]);// Convert.ToInt16(reader["Quantity"]);
							Upc = DatabaseObject.FromDB<String>(reader["Upc"]);// Convert.ToString(reader["Upc"]);
							LocAisle = DatabaseObject.FromDB<Int32>(reader["LocAisle"]);// Convert.ToInt32(reader["LocAisle"]);
							LocBlock = DatabaseObject.FromDB<Int32>(reader["LocBlock"]);// Convert.ToInt32(reader["LocBlock"]);
							LocSeq = DatabaseObject.FromDB<Int32>(reader["LocSeq"]);// Convert.ToInt32(reader["LocSeq"]);
							PrintDate = DatabaseObject.FromDB<DateTime>(reader["PrintDate"]);// Convert.ToDateTime(reader["PrintDate"]);
							SpecialPriceMethod = DatabaseObject.FromDB<Int16>(reader["SpecialPriceMethod"]);// Convert.ToInt16(reader["SpecialPriceMethod"]);
							SpecialPrice = DatabaseObject.FromDB<decimal>(reader["Special_Price"]);// Convert.ToDouble(reader["SpecialPrice"]);
							SpecialGroupPrice = DatabaseObject.FromDB<decimal>(reader["SpecialGroupPrice"]);// Convert.ToDouble(reader["SpecialGroupPrice"]);
							SpecialQuantity = DatabaseObject.FromDB<Int16>(reader["SpecialQuantity"]);// Convert.ToInt16(reader["SpecialQuantity"]);
							PalletCode = DatabaseObject.FromDB<Int32>(reader["PalletCode"]);// Convert.ToInt32(reader["PalletCode"]);
							UnitSp = DatabaseObject.FromDB<Double>(reader["Unit_SP"]);// Convert.ToDouble(reader["Unit_SP"]);
							WhereToBuy = DatabaseObject.FromDB<String>(reader["WhereToBuy"]);// Convert.ToString(reader["WhereToBuy"]);
							StartDate = DatabaseObject.FromDB<DateTime>(reader["Start_Date"]);// Convert.ToDateTime(reader["Start_Date"]);
							EndDate = DatabaseObject.FromDB<DateTime>(reader["End_Date"]);// Convert.ToDateTime(reader["End_Date"]);
							Rehang = DatabaseObject.FromDB<String>(reader["Rehang"]);// Convert.ToString(reader["Rehang"]);
							DealEndDate = DatabaseObject.FromDB<DateTime>(reader["DealEndDate"]);// Convert.ToDateTime(reader["DealEndDate"]);
							TagType = DatabaseObject.FromDB<String>(reader["TagType"]);// Convert.ToString(reader["TagType"]);
							BatchNo = DatabaseObject.FromDB<String>(reader["BatchNo"]);// Convert.ToString(reader["BatchNo"]);
							JobName = DatabaseObject.FromDB<String>(reader["JobName"]);// Convert.ToString(reader["JobName"]);
						}
						else
						{
							PopulateDefault();
						}
						reader.Close();
						connection.Close();
					}
				}
			}
		}

		protected override void PopulateDefault()
		{
			Description = "";
			Vendor = -1;
			CertCode = "";
			AvgDailyMovement = -1;
			Pack = -1;
			Size = "";
			UnitNp = -1;
			Uom = "";
			Hosted = -1;
			PriceMethod = -1;
			NormalPrice = -1;
			GroupPrice = -1;
			Quantity = -1;
			Upc = "";
			LocAisle = -1;
			LocBlock = -1;
			LocSeq = -1;
			PrintDate = new DateTime(1900, 1, 1);
			SpecialPriceMethod = -1;
			SpecialPrice = -1;
			SpecialGroupPrice = -1;
			SpecialQuantity = -1;
			PalletCode = -1;
			UnitSp = -1;
			WhereToBuy = "";
			StartDate = new DateTime(1900, 1, 1);
			EndDate = new DateTime(1900, 1, 1);
			Rehang = "";
			DealEndDate = new DateTime(1900, 1, 1);
			TagType = "";
			BatchNo = "";
			JobName = "";
		}

		public override Boolean Update()
		{
			if (Upc == "") return false;

			int rowsAffected = 0;

			using (SqlConnection connection = new SqlConnection(ConnectionString))
			{
				connection.Open();
				using (SqlCommand command = new SqlCommand("UPDATE POSplus_TagPrinting SET " +
					"Description = @Description, Vendor = @Vendor, Cert_Code = @Cert_Code, AvgDailyMovement = @AvgDailyMovement, " +
					"Pack = @Pack, Size = @Size, Unit_NP = @Unit_NP, Uom = @Uom, HOsted = @Hosted, PriceMethod = @PriceMethod, " +
					"Normal_Price = @Normal_Price, GroupPrice = @GroupPrice, Quantity = @Quantity, Upc = @Upc, " +
					"LocAisle = @LocAisle, LocBlock = @LocBlock, LocSeq = @LocSeq, PrintDate = @PrintDate, " +
					"SpecialPriceMethod = @SpecialPriceMethod, Special_Price = @Special_Price, SpecialGroupPrice = @SpecialGroupPrice, " +
					"SpecialQuantity = @SpecialQuantity, PalletCode = @PalletCode, Unit_SP = @Unit_SP, WhereToBuy = @WhereToBuy, " +
					"Start_Date = @Start_Date, End_Date = @End_Date, Rehang = @Rehang, DealEndDate = @DealEndDate, " +
					"TagType = @TagType, BatchNo = @BatchNo, JobName = @JobName", connection))
				{
					command.Parameters.AddWithValue("@Description", DatabaseObject.ToDB(Description));
					command.Parameters.AddWithValue("@Vendor", DatabaseObject.ToDB(Vendor));
					command.Parameters.AddWithValue("@Cert_Code", DatabaseObject.ToDB(CertCode));
					command.Parameters.AddWithValue("@AvgDailyMovement", DatabaseObject.ToDB(AvgDailyMovement));
					command.Parameters.AddWithValue("@Pack", DatabaseObject.ToDB(Pack));
					command.Parameters.AddWithValue("@Size", DatabaseObject.ToDB(Size));
					command.Parameters.AddWithValue("@Unit_NP", DatabaseObject.ToDB(UnitNp));
					command.Parameters.AddWithValue("@Uom", DatabaseObject.ToDB(Uom));
					command.Parameters.AddWithValue("@Hosted", DatabaseObject.ToDB(Hosted));
					command.Parameters.AddWithValue("@PriceMethod", DatabaseObject.ToDB(PriceMethod));
					command.Parameters.AddWithValue("@Normal_Price", DatabaseObject.ToDB(NormalPrice));
					command.Parameters.AddWithValue("@GroupPrice", DatabaseObject.ToDB(GroupPrice));
					command.Parameters.AddWithValue("@Quantity", DatabaseObject.ToDB(Quantity));
					command.Parameters.AddWithValue("@Upc", DatabaseObject.ToDB(Upc));
					command.Parameters.AddWithValue("@LocAisle", DatabaseObject.ToDB(LocAisle));
					command.Parameters.AddWithValue("@LocBlock", DatabaseObject.ToDB(LocBlock));
					command.Parameters.AddWithValue("@LocSeq", DatabaseObject.ToDB(LocSeq));
					command.Parameters.AddWithValue("@PrintDate", DatabaseObject.ToDB(PrintDate));
					command.Parameters.AddWithValue("@SpecialPriceMethod", DatabaseObject.ToDB(SpecialPriceMethod));
					command.Parameters.AddWithValue("@Speical_Price", DatabaseObject.ToDB(SpecialPrice));
					command.Parameters.AddWithValue("@SpeicalGroupPrice", DatabaseObject.ToDB(SpecialGroupPrice));
					command.Parameters.AddWithValue("@SpeicalQuantity", DatabaseObject.ToDB(SpecialQuantity));
					command.Parameters.AddWithValue("@PalletCode", DatabaseObject.ToDB(PalletCode));
					command.Parameters.AddWithValue("@Unit_SP", DatabaseObject.ToDB(UnitSp));
					command.Parameters.AddWithValue("@WhereToBuy", DatabaseObject.ToDB(WhereToBuy));
					command.Parameters.AddWithValue("@Start_Date", DatabaseObject.ToDB(StartDate));
					command.Parameters.AddWithValue("@End_Date", DatabaseObject.ToDB(EndDate));
					command.Parameters.AddWithValue("@Rehang", Rehang);
					command.Parameters.AddWithValue("@DealEndDate", DatabaseObject.ToDB(DealEndDate));
					command.Parameters.AddWithValue("@TagType", DatabaseObject.ToDB(TagType));
					command.Parameters.AddWithValue("@BatchNo", DatabaseObject.ToDB(BatchNo));
					command.Parameters.AddWithValue("@JobName", DatabaseObject.ToDB(JobName));
					rowsAffected = command.ExecuteNonQuery();
					connection.Close();
				}
			}

			return rowsAffected > 0;
		}

		public override Boolean Delete()
		{
			int rowsAffected = 0;

			using (SqlConnection connection = new SqlConnection(ConnectionString))
			{
				connection.Open();
				using (SqlCommand command = new SqlCommand("DELETE FROM POSplus_TagPrinting " +
					"WHERE Upc = @Upc "//AND ISNULL(LocAisle, -1) = ISNULL(@LocAisle,-1) AND ISNULL(LocBlock, -1) = ISNULL(@LocBlock,-1) " +
					//"AND ISNULL(LocSeq, -1) = ISNULL(@LocSeq,-1)"
					,connection))
				{
					command.Parameters.AddWithValue("@Upc", Upc);
					command.Parameters.AddWithValue("@LocAisle", LocAisle);
					command.Parameters.AddWithValue("@LocBlock", LocBlock);
					command.Parameters.AddWithValue("@LocSeq", LocSeq);
					rowsAffected = command.ExecuteNonQuery();
					connection.Close();
					Upc = "";
					LocAisle = -1;
					LocBlock = -1;
					LocSeq = -1;
				}
				connection.Close();
			}
			return rowsAffected > 0;
		}

		public static List<Tag> GetAllWithJobName(String connectionString, String jobName)
		{
			List<Tag> results = new List<Tag>();
			using (SqlConnection connection = new SqlConnection(connectionString))
			{
				connection.Open();
				using (SqlCommand command = new SqlCommand("SELECT * FROM POSplus_TagPrinting WHERE " +
					"JobName = @JobName", connection))
				{
					command.Parameters.AddWithValue("@JobName", jobName);
					using (SqlDataReader reader = command.ExecuteReader())
					{
						while (reader.Read())
						{
							Tag tag = new Tag(connectionString);
							tag.Description = DatabaseObject.FromDB<String>(reader["Description"]);// Convert.ToString(reader["Description"]);
							tag.Vendor = DatabaseObject.FromDB<Int32>(reader["Vendor"]);// Convert.ToInt32(reader["Vendor"]);
							tag.CertCode = DatabaseObject.FromDB<String>(reader["Cert_Code"]);// Convert.ToString(reader["CertCode"]);
							tag.AvgDailyMovement = DatabaseObject.FromDB<Double>(reader["AvgDailyMovement"]);// Convert.ToDouble(reader["AvgDailyMovement"]);
							tag.Pack = DatabaseObject.FromDB<Int16>(reader["Pack"]);// Convert.ToInt16(reader["Pack"]);
							tag.Size = DatabaseObject.FromDB<String>(reader["Size"]);// Convert.ToString(reader["Size"]);
							tag.UnitNp = DatabaseObject.FromDB<Double>(reader["Unit_NP"]);// Convert.ToDouble(reader["UnitNp"]);
							tag.Uom = DatabaseObject.FromDB<String>(reader["Uom"]);// Convert.ToString(reader["Uom"]);
							tag.Hosted = DatabaseObject.FromDB<Int32>(reader["Hosted"]);// Convert.ToInt32(reader["Hosted"]);
							tag.PriceMethod = DatabaseObject.FromDB<Int16>(reader["PriceMethod"]);// Convert.ToInt16(reader["PriceMethod"]);
							tag.NormalPrice = DatabaseObject.FromDB<Decimal>(reader["Normal_Price"]);// Convert.ToDouble(reader["Normal_Price"]);
							tag.GroupPrice = DatabaseObject.FromDB<decimal>(reader["GroupPrice"]);// Convert.ToDouble(reader["GroupPrice"]);
							tag.Quantity = DatabaseObject.FromDB<Int16>(reader["Quantity"]);// Convert.ToInt16(reader["Quantity"]);
							tag.Upc = DatabaseObject.FromDB<String>(reader["Upc"]);// Convert.ToString(reader["Upc"]);
							tag.LocAisle = DatabaseObject.FromDB<Int32>(reader["LocAisle"]);// Convert.ToInt32(reader["LocAisle"]);
							tag.LocBlock = DatabaseObject.FromDB<Int32>(reader["LocBlock"]);// Convert.ToInt32(reader["LocBlock"]);
							tag.LocSeq = DatabaseObject.FromDB<Int32>(reader["LocSeq"]);// Convert.ToInt32(reader["LocSeq"]);
							tag.PrintDate = DatabaseObject.FromDB<DateTime>(reader["PrintDate"]);// Convert.ToDateTime(reader["PrintDate"]);
							tag.SpecialPriceMethod = DatabaseObject.FromDB<Int16>(reader["SpecialPriceMethod"]);// Convert.ToInt16(reader["SpecialPriceMethod"]);
							tag.SpecialPrice = DatabaseObject.FromDB<decimal>(reader["Special_Price"]);// Convert.ToDouble(reader["SpecialPrice"]);
							tag.SpecialGroupPrice = DatabaseObject.FromDB<decimal>(reader["SpecialGroupPrice"]);// Convert.ToDouble(reader["SpecialGroupPrice"]);
							tag.SpecialQuantity = DatabaseObject.FromDB<Int16>(reader["SpecialQuantity"]);// Convert.ToInt16(reader["SpecialQuantity"]);
							tag.PalletCode = DatabaseObject.FromDB<Int32>(reader["PalletCode"]);// Convert.ToInt32(reader["PalletCode"]);
							tag.UnitSp = DatabaseObject.FromDB<Double>(reader["Unit_SP"]);// Convert.ToDouble(reader["Unit_SP"]);
							tag.WhereToBuy = DatabaseObject.FromDB<String>(reader["WhereToBuy"]);// Convert.ToString(reader["WhereToBuy"]);
							tag.StartDate = DatabaseObject.FromDB<DateTime>(reader["Start_Date"]);// Convert.ToDateTime(reader["Start_Date"]);
							tag.EndDate = DatabaseObject.FromDB<DateTime>(reader["End_Date"]);// Convert.ToDateTime(reader["End_Date"]);
							tag.Rehang = DatabaseObject.FromDB<String>(reader["Rehang"]);// Convert.ToString(reader["Rehang"]);
							tag.DealEndDate = DatabaseObject.FromDB<DateTime>(reader["DealEndDate"]);// Convert.ToDateTime(reader["DealEndDate"]);
							tag.TagType = DatabaseObject.FromDB<String>(reader["TagType"]);// Convert.ToString(reader["TagType"]);
							tag.BatchNo = DatabaseObject.FromDB<String>(reader["BatchNo"]);// Convert.ToString(reader["BatchNo"]);
							tag.JobName = DatabaseObject.FromDB<String>(reader["JobName"]);// Convert.ToString(reader["JobName"]);
							results.Add(tag);
						}
						reader.Close();
					}
				}
				connection.Close();
			}
			return results;
		}

		public static List<Tag> GetAll(String connectionString)
		{
			List<Tag> results = new List<Tag>();

			using (SqlConnection connection = new SqlConnection(connectionString))
			{
				connection.Open();
				using (SqlCommand command = new SqlCommand("SELECT * FROM POSplus_TagPrinting", connection))
				{
					using (SqlDataReader reader = command.ExecuteReader())
					{
						while (reader.Read())
						{
							Tag tag = new Tag(connectionString);
							tag.Description = DatabaseObject.FromDB<String>(reader["Description"]);// Convert.ToString(reader["Description"]);
							tag.Vendor = DatabaseObject.FromDB<Int32>(reader["Vendor"]);// Convert.ToInt32(reader["Vendor"]);
							tag.CertCode = DatabaseObject.FromDB<String>(reader["Cert_Code"]);// Convert.ToString(reader["CertCode"]);
							tag.AvgDailyMovement = DatabaseObject.FromDB<Double>(reader["AvgDailyMovement"]);// Convert.ToDouble(reader["AvgDailyMovement"]);
							tag.Pack = DatabaseObject.FromDB<Int16>(reader["Pack"]);// Convert.ToInt16(reader["Pack"]);
							tag.Size = DatabaseObject.FromDB<String>(reader["Size"]);// Convert.ToString(reader["Size"]);
							tag.UnitNp = DatabaseObject.FromDB<Double>(reader["Unit_NP"]);// Convert.ToDouble(reader["UnitNp"]);
							tag.Uom = DatabaseObject.FromDB<String>(reader["Uom"]);// Convert.ToString(reader["Uom"]);
							tag.Hosted = DatabaseObject.FromDB<Int32>(reader["Hosted"]);// Convert.ToInt32(reader["Hosted"]);
							tag.PriceMethod = DatabaseObject.FromDB<Int16>(reader["PriceMethod"]);// Convert.ToInt16(reader["PriceMethod"]);
							tag.NormalPrice = DatabaseObject.FromDB<Decimal>(reader["Normal_Price"]);// Convert.ToDouble(reader["Normal_Price"]);
							tag.GroupPrice = DatabaseObject.FromDB<decimal>(reader["GroupPrice"]);// Convert.ToDouble(reader["GroupPrice"]);
							tag.Quantity = DatabaseObject.FromDB<Int16>(reader["Quantity"]);// Convert.ToInt16(reader["Quantity"]);
							tag.Upc = DatabaseObject.FromDB<String>(reader["Upc"]);// Convert.ToString(reader["Upc"]);
							tag.LocAisle = DatabaseObject.FromDB<Int32>(reader["LocAisle"]);// Convert.ToInt32(reader["LocAisle"]);
							tag.LocBlock = DatabaseObject.FromDB<Int32>(reader["LocBlock"]);// Convert.ToInt32(reader["LocBlock"]);
							tag.LocSeq = DatabaseObject.FromDB<Int32>(reader["LocSeq"]);// Convert.ToInt32(reader["LocSeq"]);
							tag.PrintDate = DatabaseObject.FromDB<DateTime>(reader["PrintDate"]);// Convert.ToDateTime(reader["PrintDate"]);
							tag.SpecialPriceMethod = DatabaseObject.FromDB<Int16>(reader["SpecialPriceMethod"]);// Convert.ToInt16(reader["SpecialPriceMethod"]);
							tag.SpecialPrice = DatabaseObject.FromDB<decimal>(reader["Special_Price"]);// Convert.ToDouble(reader["SpecialPrice"]);
							tag.SpecialGroupPrice = DatabaseObject.FromDB<decimal>(reader["SpecialGroupPrice"]);// Convert.ToDouble(reader["SpecialGroupPrice"]);
							tag.SpecialQuantity = DatabaseObject.FromDB<Int16>(reader["SpecialQuantity"]);// Convert.ToInt16(reader["SpecialQuantity"]);
							tag.PalletCode = DatabaseObject.FromDB<Int32>(reader["PalletCode"]);// Convert.ToInt32(reader["PalletCode"]);
							tag.UnitSp = DatabaseObject.FromDB<Double>(reader["Unit_SP"]);// Convert.ToDouble(reader["Unit_SP"]);
							tag.WhereToBuy = DatabaseObject.FromDB<String>(reader["WhereToBuy"]);// Convert.ToString(reader["WhereToBuy"]);
							tag.StartDate = DatabaseObject.FromDB<DateTime>(reader["Start_Date"]);// Convert.ToDateTime(reader["Start_Date"]);
							tag.EndDate = DatabaseObject.FromDB<DateTime>(reader["End_Date"]);// Convert.ToDateTime(reader["End_Date"]);
							tag.Rehang = DatabaseObject.FromDB<String>(reader["Rehang"]);// Convert.ToString(reader["Rehang"]);
							tag.DealEndDate = DatabaseObject.FromDB<DateTime>(reader["DealEndDate"]);// Convert.ToDateTime(reader["DealEndDate"]);
							tag.TagType = DatabaseObject.FromDB<String>(reader["TagType"]);// Convert.ToString(reader["TagType"]);
							tag.BatchNo = DatabaseObject.FromDB<String>(reader["BatchNo"]);// Convert.ToString(reader["BatchNo"]);
							tag.JobName = DatabaseObject.FromDB<String>(reader["JobName"]);// Convert.ToString(reader["JobName"]);
							results.Add(tag);
						}
						reader.Close();
					}
					connection.Close();
				}
				return results;
			}
		}


		public override Boolean Create()
		{
			int rowsAffected = 0;

			using (SqlConnection connection = new SqlConnection(ConnectionString))
			{
				connection.Open();
				using (SqlCommand command = new SqlCommand("INSERT INTO POSplus_TagPrinting " +
					"(Description, Vendor, Cert_Code, AvgDailyMovement, Pack, Size, Unit_NP, " +
					"Uom, Hosted, PriceMethod, Normal_Price, GroupPrice, Quantity, Upc, LocAisle, " +
					"LocBlock, LocSeq, PrintDate, SpecialPriceMethod, Special_Price, SpecialGroupPrice, " +
					"SpecialQuantity, PalletCode, Unit_SP, WhereToBuy, Start_Date, End_Date, Rehang, " +
					"DealEndDate, TagType, BatchNo, JobName) VALUES (@Description, @Vendor, @Cert_Code, @AvgDailyMovement, @Pack, @Size, @Unit_NP, " +
					"@Uom, @Hosted, @PriceMethod, @Normal_Price, @GroupPrice, @Quantity, @Upc, @LocAisle, " +
					"@LocBlock, @LocSeq, @PrintDate, @SpecialPriceMethod, @Special_Price, @SpecialGroupPrice, " +
					"@SpecialQuantity, @PalletCode, @Unit_SP, @WhereToBuy, @Start_Date, @End_Date, @Rehang, " +
					"@DealEndDate, @TagType, @BatchNo, @JobName)", connection))
				{
					command.Parameters.AddWithValue("@Description", DatabaseObject.ToDB(Description));
					command.Parameters.AddWithValue("@Vendor", DatabaseObject.ToDB(Vendor));
					command.Parameters.AddWithValue("@Cert_Code", DatabaseObject.ToDB(CertCode));
					command.Parameters.AddWithValue("@AvgDailyMovement", DatabaseObject.ToDB(AvgDailyMovement));
					command.Parameters.AddWithValue("@Pack", DatabaseObject.ToDB(Pack));
					command.Parameters.AddWithValue("@Size", DatabaseObject.ToDB(Size));
					command.Parameters.AddWithValue("@Unit_NP", DatabaseObject.ToDB(UnitNp));
					command.Parameters.AddWithValue("@Uom", DatabaseObject.ToDB(Uom));
					command.Parameters.AddWithValue("@Hosted", DatabaseObject.ToDB(Hosted));
					command.Parameters.AddWithValue("@PriceMethod", DatabaseObject.ToDB(PriceMethod));
					command.Parameters.AddWithValue("@Normal_Price", DatabaseObject.ToDB(NormalPrice));
					command.Parameters.AddWithValue("@GroupPrice", DatabaseObject.ToDB(GroupPrice));
					command.Parameters.AddWithValue("@Quantity", DatabaseObject.ToDB(Quantity));
					command.Parameters.AddWithValue("@Upc", DatabaseObject.ToDB(Upc));
					command.Parameters.AddWithValue("@LocAisle", DatabaseObject.ToDB(LocAisle));
					command.Parameters.AddWithValue("@LocBlock", DatabaseObject.ToDB(LocBlock));
					command.Parameters.AddWithValue("@LocSeq", DatabaseObject.ToDB(LocSeq));
					command.Parameters.AddWithValue("@PrintDate", DatabaseObject.ToDB(PrintDate));
					command.Parameters.AddWithValue("@SpecialPriceMethod", DatabaseObject.ToDB(SpecialPriceMethod));
					command.Parameters.AddWithValue("@Speical_Price", DatabaseObject.ToDB(SpecialPrice));
					command.Parameters.AddWithValue("@SpeicalGroupPrice", DatabaseObject.ToDB(SpecialGroupPrice));
					command.Parameters.AddWithValue("@SpeicalQuantity", DatabaseObject.ToDB(SpecialQuantity));
					command.Parameters.AddWithValue("@PalletCode", DatabaseObject.ToDB(PalletCode));
					command.Parameters.AddWithValue("@Unit_SP", DatabaseObject.ToDB(UnitSp));
					command.Parameters.AddWithValue("@WhereToBuy", DatabaseObject.ToDB(WhereToBuy));
					command.Parameters.AddWithValue("@Start_Date", DatabaseObject.ToDB(StartDate));
					command.Parameters.AddWithValue("@End_Date", DatabaseObject.ToDB(EndDate));
					command.Parameters.AddWithValue("@Rehang", Rehang);
					command.Parameters.AddWithValue("@DealEndDate", DatabaseObject.ToDB(DealEndDate));
					command.Parameters.AddWithValue("@TagType", DatabaseObject.ToDB(TagType));
					command.Parameters.AddWithValue("@BatchNo", DatabaseObject.ToDB(BatchNo));
					command.Parameters.AddWithValue("@JobName", DatabaseObject.ToDB(JobName));
					rowsAffected = command.ExecuteNonQuery();
					connection.Close();
				}
			}

			return rowsAffected > 0;
		}

		public JobType PrintJobType
		{
			get
			{
				return _jobType;
			}
			set
			{
				_jobType = value;
			}
		}
	}
}
